package com.carleasoft.mps.cms.business.user.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carleasoft.mps.cms.business.leave.bean.vo.UserListVo;
import com.carleasoft.mps.cms.business.user.bean.UserSkill;
import com.carleasoft.mps.cms.business.user.bean.UserSkillType;
import com.carleasoft.mps.cms.business.user.bean.po.UserSkillPo;
import com.carleasoft.mps.cms.business.user.service.UserSkillService;
import com.carleasoft.mps.cms.business.user.service.UserSkillTypeService;
import com.carleasoft.mps.cms.business.write.bean.vo.UserListVos;
import com.carleasoft.mps.core.result.R;
import com.carleasoft.mps.core.user.ThreadUserContext;
import com.carleasoft.mps.core.utils.IBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zang
 * @since 2023-05-25
 */
@RestController
@RequestMapping("/userSkill")
public class UserSkillController {
    @Autowired
    private UserSkillService userSkillService;
    @Autowired
    private UserSkillTypeService userSkillTypeService;

    /**
     * @author zang
     * @desc 分页查询用户
     * @date 2023-05-25
     */
    @PostMapping("/pageUserSkill")
    public R pageUserSkill(@RequestBody UserSkillPo userSkillPo) {
        Page page = new Page(userSkillPo.getCurrent(), userSkillPo.getSize());
        Page<UserSkill> res = userSkillService.pageUserSkill(page, userSkillPo);
        return R.ok(res);
    }

    /**
     * @author zang
     * @desc 新增用户信息
     * @date 2023-05-25
     */
    @PostMapping("/saveUserSkill")
    public R saveUserSkill(@RequestBody UserSkill userSkill) {
        Boolean flag = userSkillService.saveUserSkill(userSkill);
        if (flag) {
            return R.ok();
        } else {
            return R.failed("0000001", "存在用户已添加,请重新选择用户!");
        }
    }

    /**
     * 根据部门查询人员列表
     * @param userSkill
     * @return
     */
    @PostMapping("/deptCodeByUserList")
    public R deptCodeByUserList(@RequestBody UserSkill userSkill) {
        IBeanUtil.paramVerify(userSkill, "deptCode");
        List<UserListVos> UserListVos = userSkillService.deptCodeByUserList(userSkill);
        return R.ok(UserListVos);
    }


    /**
     * @author zang
     * @desc 更新用户信息
     * @date 2023-05-25
     */
    @PostMapping("/updateUserSkill")
    public R updateUserSkill(@RequestBody UserSkill userSkill) {
        Boolean flag = userSkillService.updateUserSkill(userSkill);
        if (flag) {
            return R.ok();
        } else {
            return R.failed("0000001", "该用户已添加");
        }
    }

    /**
     * @author zang
     * @desc 删除用户信息
     * @date 2023-05-25
     */
    @PostMapping("/deleteUserSkill")
    public R deleteUserSkill(@RequestBody UserSkill userSkill) {
        userSkillService.deleteUserSkill(userSkill);
        return R.ok();
    }


    /**
     * @author zang
     * @desc 获取人才类型分类
     * @date 2023-06-13
     */
    @PostMapping("/selSkillType")
    public R selSkillType() {
        List<UserSkillType> res = userSkillTypeService.getAllWrapper();
        return R.ok(res);
    }

    /**
     * @author zang
     * @desc 保存更新人才类型分类
     * @date 2023-06-13
     */
    @PostMapping("/updateSkillType")
    public R updateSkillType(@RequestBody UserSkillType userSkillType) {
        userSkillTypeService.updateSkillType(userSkillType);
        return R.ok();
    }


    /**
     * @author zang
     * @desc 删除人才类型
     * @date 2023-06-13
     */
    @PostMapping("/deleteSkillType")
    public R deleteSkillType(@RequestBody UserSkillType userSkillType) {
        boolean flag = userSkillTypeService.deleteSkillType(userSkillType);
        if (flag) {
            return R.ok();
        } else {
            return R.failed("0000001", "该人才分类型下有人才，无法删除");
        }
    }



}

